﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using MyFinanceManager.Controls;

namespace MyFinanceManager
{
    public partial class ucTime : FiringUserControl
    {
        public DateTime Value
        {
            get
            {
                int minute = this.upAndDowner3.Value;
                minute += this.upAndDowner2.Value * 10;
                int hour = this.upAndDowner1.Value;
                hour += this.upAndDowner0.Value * 10;
                try
                {
                    return new DateTime(1, 1, 1, hour, minute, 0);
                }
                catch
                {
                    return new DateTime();
                }
            }
        }

        public ucTime()
        {
            InitializeComponent();

            this.upAndDowner1.Value = DateTime.Now.Hour - ((int)(DateTime.Now.Hour / 10)) * 10;
            this.upAndDowner3.Value = DateTime.Now.Minute - ((int)(DateTime.Now.Minute / 10)) * 10;

            if (DateTime.Now.Hour > 10)
                this.upAndDowner0.Value = (int)(DateTime.Now.Hour / 10);
            if (DateTime.Now.Minute > 10)
                this.upAndDowner2.Value = (int)(DateTime.Now.Minute / 10);

            this.upAndDowner0.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner1.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner2.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner3.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
        }

        void upAndDowner_ValueChanged(object sender, EventArgs e)
        {
            FireNewValueAvailable(this.Value.Hour.ToString("00") + ":" + this.Value.Minute.ToString("00"));
        }
    }
}
